package com.jeework.modules.sys.web;

import com.jeework.common.utils.CookieUtils;
import com.jeework.common.utils.StringUtils;
import com.jeework.common.web.BaseController;
import com.jeework.modules.sys.entity.User;
import com.jeework.modules.sys.utils.UserUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "${adminPath}/sys")
public class SysController extends BaseController {

    @RequestMapping("switchSkin/select")
    public String swtichSkin(HttpServletRequest request, HttpServletResponse response, Model model) {
        return "modules/sys/switchSkin";
    }

    @RequestMapping("switchSkin/{skinName}")
    public String doSwtichSkin(@PathVariable String skinName,HttpServletRequest request, HttpServletResponse response) {
        User user = UserUtils.getUser();
        if (StringUtils.isNotBlank(skinName) && !"select".equals(skinName)){
            CookieUtils.setCookie(response, "skinName", skinName);
            return "redirect:" +adminPath;
        }
        return "modules/sys/switchSkin";
    }

}
